package com.wen.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wen.common.Result;
import com.wen.entity.Course;
import com.wen.service.CourseService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 课程
 *
 * @author dhh
 */
@RestController
@AllArgsConstructor
@RequestMapping("/course")
public class CourseController {

    private final CourseService courseService;

    //    添加设备信息
    @PostMapping
    public Result<?> save(@RequestBody Course course) {
        courseService.save(course);
        return Result.success();
    }

    //    更新
    @PutMapping
    public Result<?> update(@RequestBody Course course) {
        courseService.updateById(course);
        return Result.success();
    }

    //    s删除
    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable Long id) {
        courseService.removeById(id);
        return Result.success();
    }

    //    查询
    @GetMapping
    public Result<?> findPage(@RequestParam(defaultValue = "1") Integer pageNum,
                              @RequestParam(defaultValue = "10") Integer pageSize) {
        LambdaQueryWrapper<Course> wrapper = Wrappers.<Course>lambdaQuery();
        Page<Course> NewsPage = courseService.page(new Page<>(pageNum, pageSize), wrapper);
        return Result.success(NewsPage);
    }
}
